package com.example.demo.config;

import com.example.demo.basic.DataBaseContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * 类描述: 动态数据源
 *
 * @auth zhanglei
 * @date 2019/3/8 9:04
 **/
@Slf4j
public class DynamicDataSource extends AbstractRoutingDataSource {

    @Override
    protected Object determineCurrentLookupKey() {
        Object obj = DataBaseContextHolder.getDBID();
        log.debug("DynamicDataSource, dateSourceId : " + obj);
        return obj;
    }

    public void refreshDbConfigForMVC() {
        super.afterPropertiesSet();
    }
}
